const Product = require('../../../table/mongo/product');

module.exports = {
  async lists(req, res) {
    let reData = req.gets();

    let page = Number(reData.page) || 1;
    let count = Number(reData.count) || 10;

    let data = await Product.find({})
      .skip((page - 1) * count)
      .limit(count)
      .exec();

    res.success("获取成功", data);
  },
  async product(req, res) {
    let id = req.params.id;
    if (!!id) {
      try {
        let data = await Product.find({ _id: id }).exec();
        if(!!data) {
            res.success("获取成功", data[0]);
        }
        res.error("产品不存在");
      } catch (e) {
        res.error("获取失败");
      }
    } else {
      res.error("产品 id 出错");
    }
  }
};
